home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python151_Src.lha / Python1.5_Source / Amiga / _fstat.c < prev    next >
C/C++ Source or Header  |  1998-12-25  |  2KB  |  81 lines

  1. RCS_ID_C="$Id: _fstat.c,v 4.2 1995/09/17 20:52:30 jraja Exp $";
  2. /*
  3.  *      _fstat.c - fstat() for Network Support Library (SAS/C)
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <sys/types.h>
  11. #include <sys/socket.h>
  12. #include <sys/stat.h>
  13. #include <errno.h>
  14.  
  15. #include <string.h>
  16. #include <stdlib.h>
  17.  
  18. /* DOS 3.0 and MuFS extensions to file info block */
  19. #include "fibex.h"
  20. #include <proto/dos.h>
  21. #include <proto/utility.h>
  22.  
  23. #include <ios1.h>
  24. #include "libcheck.h"
  25.  
  26. int fstat(int fd, struct stat *st)
  27. {
  28.   struct UFB *ufb = chkufb(fd);
  29.  
  30.   if (st == NULL || ((1 & (long)st) == 1)) {
  31.     errno = EFAULT;
  32.     return -1;
  33.   }
  34.  
  35.   if (ufb == NULL || ufb->ufbflg == 0) {
  36.     errno = EBADF;
  37.     return -1;
  38.   }
  39.  
  40.   if (ufb->ufbflg & UFB_SOCK) { /* a socket */
  41.     long value;
  42.     long size = sizeof(value);
  43.  
  44.     /* Needs both usergroup.library and bsdsocket.library -- I.J. */
  45.     if(!checkusergrouplib() || !checksocketlib()) return -1;
  46.  
  47.     bzero(st, sizeof(*st));
  48.  
  49.     /* st->st_dev = ??? */
  50.     st->st_mode = S_IFSOCK | S_IRUSR | S_IWUSR;
  51.     st->st_uid = geteuid();
  52.     st->st_gid = getegid();
  53.  
  54.     if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &size) == 0)
  55.       st->st_blksize = value;
  56.  
  57.     return 0;
  58.   } else { /* ordinal file */
  59.     /* test if it is a NIL: file handle (ExamineFH() crashes on those!) */
  60.     if (((struct FileHandle *)BADDR((BPTR)ufb->ufbfh))->fh_Type == NULL) {
  61.       /* It is NIL:, make up something... */
  62.       bzero(st, sizeof(*st));
  63.       st->st_mode = S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO;
  64.       return 0;
  65.     }
  66.     else {
  67.       if (ExamineFH(ufb->ufbfh, __dostat_fib)) {
  68.     __dostat(__dostat_fib, st);
  69.     st->st_dev = (dev_t)((struct FileHandle *)BADDR(ufb->ufbfh))->fh_Type;
  70.     return 0;
  71.       } else {
  72.     errno = EIO;
  73.     return -1;
  74.       }
  75.     }
  76.   }
  77. }
  78.  
  79.  
  80.  
  81.